package main

import (
	"fmt"
	"time"
)

func main() {
	for val := range handleMsg() {
		fmt.Println("index", val)
	}
}

func handleMsg() <-chan int {		//返回一个只读的管道
	ch := make(chan int)
	t := time.Tick(time.Second * 1)
	index := 0
	go func(index int) {
		for {
			select {
			case <-t:
				ch <- index
				index++
			}
		}
	}(index)
	return ch
}
